/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template fie, choose Tools | Templates
 * and open the template in the editor.
 */
package tienda.zapateria.siszap.gui.control;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileFilter;
import org.rx.cr.gui.JInternalFrameUC;
import org.rx.cr.util.Utilitarios;
import static org.rx.cr.util.Utilitarios.alinearDatosColumnaTablaCentro;
import static org.rx.cr.util.Utilitarios.disableComponent;
import static org.rx.cr.util.Utilitarios.formateaAnchoColumnaTabla;
import static org.rx.cr.util.Utilitarios.getFileExtencion;
import static org.rx.cr.util.Utilitarios.resizeIcon;
import tienda.zapateria.siszap.be.BEArticulo;
import tienda.zapateria.siszap.be.BEMarca;
import tienda.zapateria.siszap.be.BERelacionTalla;
import tienda.zapateria.siszap.be.BETalla;
import tienda.zapateria.siszap.be.BETipo;
import tienda.zapateria.siszap.bl.BLArticulo;
import tienda.zapateria.siszap.bl.BLRelacionTalla;
import tienda.zapateria.siszap.bl.BLTalla;
import tienda.zapateria.siszap.gui.JF_Principal;
import tienda.zapateria.siszap.gui.control.model.ModelArticulo;
import tienda.zapateria.siszap.gui.control.model.ModeloRelacionTalla;
import tienda.zapateria.siszap.util.UtilMarca;
import tienda.zapateria.siszap.util.UtilProveedor;
import tienda.zapateria.siszap.util.UtilTipo;

/**
 *
 * @author max
 */
public class JIF_AdministrarArticulo extends JInternalFrameUC {

    /**
     * Creates new form JIF_AdministrarCalzado
     */
    JF_Principal parent;
    BEArticulo be;
    BLArticulo bl;
    ModelArticulo model;

    BETalla beTalla;
    BLTalla blTalla;

    UtilTipo utilTipo;
    UtilProveedor utilProveedor;
    UtilMarca utilMarca;

    BERelacionTalla beRelacionTalla;
    BLRelacionTalla blRelacionTalla;
    private JFileChooser jfc;
    private File foto1;

    ModeloRelacionTalla modeloRelacionTalla;
    public String registro;

    public static final int ARCH_FOTOGRAFIA1 = 1;

    public JIF_AdministrarArticulo(JF_Principal parent) {
        initComponents();
        this.parent = parent;
        bl = new BLArticulo(parent.getConf());
        blRelacionTalla = new BLRelacionTalla(parent.getConf());
        model = new ModelArticulo();
        jtArticulo.setModel(model);
        personalizaVistaTabla();
        utilMarca = new UtilMarca(parent.getConf());
        utilTipo = new UtilTipo(parent.getConf());
        utilProveedor = new UtilProveedor(parent.getConf());

        defaultFoto1();
        jfc = new JFileChooser();
        jfc.setFileFilter(new FileFilter() {
            //<editor-fold defaultstate="collapsed" desc="Filter">
            @Override
            public boolean accept(File f) {
                if (f.isDirectory()) {
                    return true;
                } else if (f.isFile()) {
                    if (getFileExtencion(f.getName().toLowerCase()).equals("jpg")
                            || getFileExtencion(f.getName().toLowerCase()).equals("jpeg")
                            || getFileExtencion(f.getName().toLowerCase()).equals("jpe")
                            || getFileExtencion(f.getName().toLowerCase()).equals("jfif")
                            || getFileExtencion(f.getName().toLowerCase()).equals("png")
                            || getFileExtencion(f.getName().toLowerCase()).equals("gif")
                            || getFileExtencion(f.getName().toLowerCase()).equals("bmp")) {
                        return true;
                    } else {
                        return false;
                    }
                } else {
                    return false;
                }
            }

            @Override
            public String getDescription() {
                return "Archivos Soportados(*.jpg,*.jpeg,*,jpe,*.jfif,*.png,*.gif,*.bmp)";
            }
            //</editor-fold>
        });
        jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
        jfc.setApproveButtonText("Seleccionar");

        modeloRelacionTalla = new ModeloRelacionTalla();
        jtTalla.setModel(modeloRelacionTalla);

        blTalla = new BLTalla(parent.getConf());
        _init();

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        txfBuscar = new javax.swing.JTextField();
        jbBuscar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtArticulo = new javax.swing.JTable();
        jPanel2 = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        jbActualizarMarca = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        txfColor = new javax.swing.JTextField();
        txfMaterial = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        txaDescripcion = new javax.swing.JTextArea();
        jLabel1 = new javax.swing.JLabel();
        jcbTipo = new javax.swing.JComboBox();
        jLabel11 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jcbMarca = new javax.swing.JComboBox();
        jbActualizarTipo = new javax.swing.JButton();
        jbAgregarTipo = new javax.swing.JButton();
        jbAgregarMarca = new javax.swing.JButton();
        txfUbicacion = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        txfPrecioCompra = new javax.swing.JTextField();
        txfPrecioVenta = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jInternalFrame1 = new javax.swing.JInternalFrame();
        jbAgregar = new javax.swing.JButton();
        jbEditar = new javax.swing.JButton();
        jbGuardar = new javax.swing.JButton();
        jbCancelar = new javax.swing.JButton();
        jbSalir = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jtTalla = new javax.swing.JTable();
        jbQuitarTalla = new javax.swing.JButton();
        jbaAgregarTalla = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        jlFoto = new javax.swing.JLabel();
        jbCargar = new javax.swing.JButton();

        setClosable(true);
        setIconifiable(true);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "BUSCAR ARTÍCULO", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        jbBuscar.setText("Buscar");

        jtArticulo.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(jtArticulo);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(txfBuscar, javax.swing.GroupLayout.DEFAULT_SIZE, 312, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbBuscar))
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txfBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbBuscar))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 211, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "ARTÍCULO", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        jbActualizarMarca.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tienda/zapateria/siszap/imagen/small_refresh.png"))); // NOI18N
        jbActualizarMarca.setBorder(null);
        jbActualizarMarca.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbActualizarMarcaActionPerformed(evt);
            }
        });

        jLabel5.setText("Descripción :");

        txaDescripcion.setColumns(20);
        txaDescripcion.setLineWrap(true);
        txaDescripcion.setRows(5);
        jScrollPane2.setViewportView(txaDescripcion);

        jLabel1.setText("Tipo :");

        jcbTipo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jLabel11.setText("Marca :");

        jLabel2.setText("Color :");

        jLabel3.setText("Material :");

        jcbMarca.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jbActualizarTipo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tienda/zapateria/siszap/imagen/small_refresh.png"))); // NOI18N
        jbActualizarTipo.setBorder(null);
        jbActualizarTipo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbActualizarTipoActionPerformed(evt);
            }
        });

        jbAgregarTipo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tienda/zapateria/siszap/imagen/small_agregar.png"))); // NOI18N
        jbAgregarTipo.setBorderPainted(false);
        jbAgregarTipo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbAgregarTipoActionPerformed(evt);
            }
        });

        jbAgregarMarca.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tienda/zapateria/siszap/imagen/small_agregar.png"))); // NOI18N
        jbAgregarMarca.setBorderPainted(false);
        jbAgregarMarca.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbAgregarMarcaActionPerformed(evt);
            }
        });

        jLabel4.setText("Ubicación :");

        jLabel8.setText("Precio de venta :");

        jLabel7.setText("Precio de compra :");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel5)
                    .addComponent(jLabel1)
                    .addComponent(jLabel11)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4)
                    .addComponent(jLabel8)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txfPrecioCompra)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 201, Short.MAX_VALUE)
                            .addGroup(jPanel5Layout.createSequentialGroup()
                                .addComponent(jcbTipo, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jbAgregarTipo, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jbActualizarTipo, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel5Layout.createSequentialGroup()
                                .addComponent(jcbMarca, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jbAgregarMarca, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jbActualizarMarca, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(txfColor)
                            .addComponent(txfMaterial)
                            .addComponent(txfUbicacion))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(txfPrecioVenta))
                .addGap(0, 0, 0))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jbActualizarTipo, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbAgregarTipo, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jcbTipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel1)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jcbMarca, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel11))
                    .addComponent(jbAgregarMarca, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbActualizarMarca, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txfColor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txfMaterial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txfUbicacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txfPrecioCompra, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txfPrecioVenta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8))
                .addGap(0, 0, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jInternalFrame1Layout = new javax.swing.GroupLayout(jInternalFrame1.getContentPane());
        jInternalFrame1.getContentPane().setLayout(jInternalFrame1Layout);
        jInternalFrame1Layout.setHorizontalGroup(
            jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        jInternalFrame1Layout.setVerticalGroup(
            jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        jbAgregar.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        jbAgregar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tienda/zapateria/siszap/imagen/Nuevo.png"))); // NOI18N
        jbAgregar.setText("NUEVO");
        jbAgregar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbAgregar.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jbAgregar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbAgregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbAgregarActionPerformed(evt);
            }
        });

        jbEditar.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        jbEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tienda/zapateria/siszap/imagen/Modificar_Min.png"))); // NOI18N
        jbEditar.setText("EDITAR");
        jbEditar.setEnabled(false);
        jbEditar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbEditar.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jbEditar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbEditarActionPerformed(evt);
            }
        });

        jbGuardar.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        jbGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tienda/zapateria/siszap/imagen/Guardar_Min.png"))); // NOI18N
        jbGuardar.setText("GUARDAR");
        jbGuardar.setEnabled(false);
        jbGuardar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbGuardar.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jbGuardar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbGuardarActionPerformed(evt);
            }
        });

        jbCancelar.setFont(new java.awt.Font("Tahoma", 0, 8)); // NOI18N
        jbCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tienda/zapateria/siszap/imagen/Cancelar_Min.png"))); // NOI18N
        jbCancelar.setText("CANCELAR");
        jbCancelar.setEnabled(false);
        jbCancelar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbCancelar.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jbCancelar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbCancelarActionPerformed(evt);
            }
        });

        jbSalir.setFont(new java.awt.Font("Tahoma", 0, 8)); // NOI18N
        jbSalir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tienda/zapateria/siszap/imagen/exit_min.png"))); // NOI18N
        jbSalir.setText("SALIR");
        jbSalir.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbSalir.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jbSalir.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbSalirActionPerformed(evt);
            }
        });

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Tallas"));

        jtTalla.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane3.setViewportView(jtTalla);

        jbQuitarTalla.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tienda/zapateria/siszap/imagen/small_cancelar.png"))); // NOI18N
        jbQuitarTalla.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbQuitarTallaActionPerformed(evt);
            }
        });

        jbaAgregarTalla.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tienda/zapateria/siszap/imagen/small_agregar.png"))); // NOI18N
        jbaAgregarTalla.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbaAgregarTallaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jbaAgregarTalla, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbQuitarTalla, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(3, 3, 3))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addComponent(jbaAgregarTalla)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbQuitarTalla)
                .addGap(0, 0, Short.MAX_VALUE))
            .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Imagen"));

        jlFoto.setBackground(new java.awt.Color(0, 0, 0));
        jlFoto.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jlFoto.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jScrollPane4.setViewportView(jlFoto);

        jbCargar.setText(".....");
        jbCargar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbCargarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jbCargar, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(jScrollPane4)))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 142, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbCargar))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jbAgregar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbEditar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbGuardar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbCancelar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbSalir)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(0, 0, Short.MAX_VALUE))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(0, 508, Short.MAX_VALUE)
                    .addComponent(jInternalFrame1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 497, Short.MAX_VALUE)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jbEditar, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbAgregar, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbSalir, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(20, Short.MAX_VALUE))
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(0, 177, Short.MAX_VALUE)
                    .addComponent(jInternalFrame1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 177, Short.MAX_VALUE)))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbAgregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbAgregarActionPerformed

        // TODO add your handling code here:
    }//GEN-LAST:event_jbAgregarActionPerformed

    private void jbGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbGuardarActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jbGuardarActionPerformed

    private void jbCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbCancelarActionPerformed
        jbCargar.setEnabled(false);
        jbEditar.setEnabled(false);
    }//GEN-LAST:event_jbCancelarActionPerformed

    private void jbSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbSalirActionPerformed
        dispose();
        jbCancelar.doClick();
    }//GEN-LAST:event_jbSalirActionPerformed

    private void jbCargarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbCargarActionPerformed
        // TODO add your handling code here:
        seleccionarArchivo(ARCH_FOTOGRAFIA1);
    }//GEN-LAST:event_jbCargarActionPerformed

    private void jbActualizarTipoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbActualizarTipoActionPerformed
        // TODO add your handling code here:
        try {
            utilTipo.cargarTipo(jcbTipo);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Error al cargar el tipo" + e, "Administrar articulo", JOptionPane.INFORMATION_MESSAGE);
        }
    }//GEN-LAST:event_jbActualizarTipoActionPerformed

    private void jbAgregarTipoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbAgregarTipoActionPerformed
        // TODO add your handling code here:
        parent.insertarInternalFrame(parent.jIF_AdministrarTipo);
        jbActualizarTipo.setEnabled(true);
    }//GEN-LAST:event_jbAgregarTipoActionPerformed

    private void jbAgregarMarcaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbAgregarMarcaActionPerformed
        // TODO add your handling code here:
        parent.insertarInternalFrame(parent.jIF_AdministrarMarca);
        jbActualizarMarca.setEnabled(true);
    }//GEN-LAST:event_jbAgregarMarcaActionPerformed

    private void jbActualizarMarcaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbActualizarMarcaActionPerformed
        // TODO add your handling code here:
        try {
            utilMarca.cargarMarca(jcbMarca);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Error al cargar la marca" + e, "Administrar articulo", JOptionPane.INFORMATION_MESSAGE);
        }
    }//GEN-LAST:event_jbActualizarMarcaActionPerformed

    private void jbQuitarTallaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbQuitarTallaActionPerformed
        // TODO add your handling code here:        
        try {
            if (jtTalla.getSelectedRow() >= 0) {
                modeloRelacionTalla.remove(jtTalla.getSelectedRow());
            } else {
                JOptionPane.showMessageDialog(this, "Selecciona el elemento a eliminar.", "Atención.", JOptionPane.INFORMATION_MESSAGE);
                System.out.println("Seleccionar el elemento a eliminar");
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Error al eliminar la valuacion complementaria. " + e, "Atención.", JOptionPane.ERROR_MESSAGE);

            Logger.getLogger(JIF_AdministrarArticulo.class
                    .getName()).log(Level.SEVERE, null, e);
        }
    }//GEN-LAST:event_jbQuitarTallaActionPerformed

    private void jbaAgregarTallaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbaAgregarTallaActionPerformed
        // TODO add your handling code here:
        personalizaVistaTabla();
        parent.insertarInternalFrame(parent.jifAsignarTalla);
        personalizaVistaTabla();
    }//GEN-LAST:event_jbaAgregarTallaActionPerformed

    private void jbEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbEditarActionPerformed
        // TODO add your handling code here:

    }//GEN-LAST:event_jbEditarActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JInternalFrame jInternalFrame1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JButton jbActualizarMarca;
    private javax.swing.JButton jbActualizarTipo;
    private javax.swing.JButton jbAgregar;
    private javax.swing.JButton jbAgregarMarca;
    private javax.swing.JButton jbAgregarTipo;
    private javax.swing.JButton jbBuscar;
    private javax.swing.JButton jbCancelar;
    private javax.swing.JButton jbCargar;
    private javax.swing.JButton jbEditar;
    private javax.swing.JButton jbGuardar;
    private javax.swing.JButton jbQuitarTalla;
    private javax.swing.JButton jbSalir;
    private javax.swing.JButton jbaAgregarTalla;
    private javax.swing.JComboBox jcbMarca;
    private javax.swing.JComboBox jcbTipo;
    private javax.swing.JLabel jlFoto;
    private javax.swing.JTable jtArticulo;
    private javax.swing.JTable jtTalla;
    private javax.swing.JTextArea txaDescripcion;
    private javax.swing.JTextField txfBuscar;
    private javax.swing.JTextField txfColor;
    private javax.swing.JTextField txfMaterial;
    private javax.swing.JTextField txfPrecioCompra;
    private javax.swing.JTextField txfPrecioVenta;
    private javax.swing.JTextField txfUbicacion;
    // End of variables declaration//GEN-END:variables

    @Override
    public void _cargarCombos() throws Exception {
        utilTipo.cargarTipo(jcbTipo);
        utilMarca.cargarMarca(jcbMarca);
    }

    @Override
    public void _agregaValidadoresControl() {
        Utilitarios.addEnterDoclickEvent(new Object[][]{{txfBuscar, jbBuscar}});
        _addOperationEventsButtons(jbAgregar, jbEditar, jbGuardar, jbCancelar);
        _addRestoreDataEventsTable(jtArticulo);
        _addSearchEventsButton(jbBuscar);
        Utilitarios.addCharacterValidatorEvent(new Object[][]{ //{txfEstablecimientoSalud, ALFABETICO_CM, 160},
        //         {txfNumMaquinas, NUMERICO, 20},
        //        {txfNumTrabajadores, NUMERICO, 20},
        //                    {txfTelefono, NUMERICO, 15}
        });
    }

    @Override
    public boolean _isDatosValidosBE() {
        return Utilitarios.isDatosLlenos(new Object[][]{ // {txfEstablecimientoSalud, "Ingresar el nombre del establecimiento"},
        // {txfCodigoEstablecimiento, "Ingresar el código del establecimiento"},
        // {txfDireccion, "Ingresar la dirección del establecimiento"},
        });
    }

    @Override
    public int _registrarBE() throws Exception {

        be = new BEArticulo();
        be.setColor(txfColor.getText());
        be.setDescripcion(txaDescripcion.getText());
        be.setImagen(foto1);
        if (foto1 != null) {
            be.setExtension(getFileExtencion(foto1));
        } else {
            be.setExtension("png");
        }

        be.setMarcaid(((BEMarca) jcbMarca.getSelectedItem()).getMarcaid());
        be.setMaterial(txfMaterial.getText());
        be.setPreciocompra(Double.parseDouble(txfPrecioCompra.getText()));
        be.setPrecioventa(Double.parseDouble(txfPrecioVenta.getText()));
       
        be.setTipoid(((BETipo) jcbTipo.getSelectedItem()).getTipoid());
        be.setUbicacion(txfUbicacion.getText());

        int idInicio = bl.obtenerUltimoId();
        bl.registrar(be);
        int id = bl.obtenerUltimoId();
        if (id != idInicio) {
            JOptionPane.showMessageDialog(this, "Se ha registrado la propiedad.", "Registro de propiedad.", JOptionPane.INFORMATION_MESSAGE);

            //asignar talla
            for (BETalla s : modeloRelacionTalla.getList()) {
                beRelacionTalla = new BERelacionTalla();
                beRelacionTalla.setArticuloid(id);
                beRelacionTalla.setTallaid(s.getTallaid());
                beRelacionTalla.setStock(s.getStock());
                System.out.println("Esto es la talla. " + s.getAmericana());
                blRelacionTalla.registrar(beRelacionTalla);
            }
        }

        return 1;
    }

    @Override
    public int _guardarCambiosBE() throws Exception {
        be = model.get(jtArticulo.getSelectedRow());

        be.setColor(txfColor.getText());
        be.setDescripcion(txaDescripcion.getText());
        be.setImagen(foto1);
        if (foto1 != null) {
            be.setExtension(getFileExtencion(foto1));
        } else {
            be.setExtension("png");
        }
        be.setMarcaid(((BEMarca) jcbMarca.getSelectedItem()).getMarcaid());
        be.setMaterial(txfMaterial.getText());
        be.setPreciocompra(Double.parseDouble(txfPrecioCompra.getText()));
        be.setPrecioventa(Double.parseDouble(txfPrecioVenta.getText()));
        be.setTipoid(((BETipo) jcbTipo.getSelectedItem()).getTipoid());
        be.setUbicacion(txfUbicacion.getText());
        bl.actualizarRegistro(be);
        //asignar talla

        int idar = model.get(jtArticulo.getSelectedRow()).getArticuloid();

        if (!blRelacionTalla.listarAsignacion(idar).isEmpty()) {
            blRelacionTalla.eliminarAsignacion(idar);
        }

        for (BETalla c : modeloRelacionTalla.getList()) {
            beRelacionTalla = new BERelacionTalla();
            beRelacionTalla.setArticuloid(RetornaId(model.get(jtArticulo.getSelectedRow())));
            beRelacionTalla.setTallaid(c.getTallaid());
            beRelacionTalla.setStock(c.getStock());
            blRelacionTalla.registrar(beRelacionTalla);
        }
        return 1;
    }

    @Override
    public void _listarBEs() throws Exception {
        model.addAll(bl.buscarReferencia(txfBuscar.getText()));
        personalizaVistaTabla();
    }

    @Override
    public void _recuperarDatosBE() throws Exception {
        if (jtArticulo.getSelectedRow() >= 0) {
            be = model.get(jtArticulo.getSelectedRow());
            txfColor.setText(be.getColor());
            txaDescripcion.setText(be.getDescripcion());
            be = bl.buscar(be.getArticuloid());
            foto1 = be.getImagen();
            jlFoto.setIcon(resizeIcon(foto1, 80, 80));
            utilMarca.seleccionarMarca(be.getMarcaid(), jcbMarca);
            txfMaterial.setText(be.getMaterial());
            txfPrecioCompra.setText(Double.toString(be.getPreciocompra()));
            txfPrecioVenta.setText(Double.toString(be.getPrecioventa()));
            utilTipo.seleccionarTipo(be.getTipoid(), jcbTipo);
            txfUbicacion.setText(be.getUbicacion());

            //asignar talla
            modeloRelacionTalla.clear();
            System.out.println("Esto es el ide de articulo: " + be.getArticuloid());

            ArrayList<BERelacionTalla> lad = blRelacionTalla.listarAsignacion(be.getArticuloid());
            System.out.println("esto es recuperacion de talla " + blRelacionTalla.listarAsignacion(be.getArticuloid()).size());
            
           
            for (BERelacionTalla a : lad) {
                System.out.println("Esto dentro del for talla: " + a.getTallaid());
                beTalla = blTalla.buscar(a.getTallaid());
                beTalla.setStock(a.getStock());
                modeloRelacionTalla.add(beTalla);
            }
            jbEditar.setEnabled(true);
        }
    }

    @Override
    public void _deshabilitarControlesDatos() {
        disableComponent(new Object[]{
            jcbTipo, txfColor, jcbMarca, txfMaterial, txfPrecioCompra,
            txfPrecioVenta, txfUbicacion, txaDescripcion,
            jbAgregarMarca, jbAgregarTipo,
            jbActualizarMarca, jbActualizarTipo, jbCargar, jbaAgregarTalla, jbQuitarTalla
        });
    }

    @Override
    public void _habilitarControlesDatos() {
        Utilitarios.enableComponent(new Object[]{
            jcbTipo, txfColor, jcbMarca, txfMaterial, txfPrecioCompra,
            txfPrecioVenta, txfUbicacion, txaDescripcion,
            jbAgregarMarca, jbAgregarTipo,
            jbActualizarMarca, jbActualizarTipo, jbCargar, jbaAgregarTalla, jbQuitarTalla

        });
    }

    @Override
    public void _resetControls() {
        Utilitarios.resetComponents(new Object[]{
            jcbTipo, txfColor, jcbMarca, txfMaterial, txfPrecioCompra,
            txfPrecioVenta, txfUbicacion, txaDescripcion,
            jbAgregarMarca, jbAgregarTipo,
            jbActualizarMarca, jbActualizarTipo, jbCargar, jbaAgregarTalla, jbQuitarTalla
        });
        jlFoto.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tienda/zapateria/siszap/imagen/anonimo.png")));
        modeloRelacionTalla.clear();
    }

    private void personalizaVistaTabla() {
        alinearDatosColumnaTablaCentro(0, jtArticulo);
        alinearDatosColumnaTablaCentro(1, jtArticulo);
        alinearDatosColumnaTablaCentro(2, jtArticulo);
        alinearDatosColumnaTablaCentro(3, jtArticulo);
        alinearDatosColumnaTablaCentro(4, jtArticulo);
        alinearDatosColumnaTablaCentro(5, jtArticulo);
        alinearDatosColumnaTablaCentro(6, jtArticulo);
        alinearDatosColumnaTablaCentro(7, jtArticulo);
        formateaAnchoColumnaTabla(0, jtArticulo, 20);
        formateaAnchoColumnaTabla(1, jtArticulo, 80);
        formateaAnchoColumnaTabla(2, jtArticulo, 80);
        formateaAnchoColumnaTabla(3, jtArticulo, 100);
        formateaAnchoColumnaTabla(4, jtArticulo, 100);
        formateaAnchoColumnaTabla(5, jtArticulo, 50);
        formateaAnchoColumnaTabla(6, jtArticulo, 50);
        formateaAnchoColumnaTabla(7, jtArticulo, 300);
    }

    void clearLista() {
        model.clear();
    }

    private void defaultFoto1() {
        foto1 = new File("conf" + File.separator + "default.png");
        if (!foto1.exists()) {
            try {
                foto1.createNewFile();
            } catch (IOException ex) {
                JOptionPane.showMessageDialog(this, "Error en imagen por defecto. " + ex, "Atencion", JOptionPane.ERROR_MESSAGE);
                ex.printStackTrace();
            }
        }

    }

    private void seleccionarArchivo(int op) {
        int rsp = -1;
        switch (op) {
            case ARCH_FOTOGRAFIA1:
                rsp = jfc.showOpenDialog(this);
                if (rsp == JFileChooser.APPROVE_OPTION) {
                    foto1 = jfc.getSelectedFile();
                    jlFoto.setIcon(resizeIcon(foto1, 97, 97));
                } else {
                    defaultFoto1();
                    jlFoto.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tienda/zapateria/siszap/imagen/anonimo.png")));
                }
                break;
        }
    }

    public void cargarComboMarca() {
        try {
            utilMarca.cargarMarca(jcbMarca);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Error al cargar marca");
        }
    }

    public void cargarComboTipo() {
        try {
            utilTipo.cargarTipo(jcbTipo);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Error al cargar tipo");
        }
    }

    void agregarTalla(BETalla componente) {
        try {
            boolean c = false;
            for (int i = 0; i < modeloRelacionTalla.getRowCount(); i++) {
                if (modeloRelacionTalla.get(i).getTallaid() == componente.getTallaid()) {
                    JOptionPane.showMessageDialog(this, "La talla ha sido seleccionado antes, por favor seleccione otro.", "Atención", JOptionPane.INFORMATION_MESSAGE);
                    c = true;
                }
            }
            if (c == false) {
                modeloRelacionTalla.add(componente);
//                try {
//                    List <BERelacionTalla> re=blRelacionTalla.buscarReferencia("");
//                    List<BETalla> lista;
//                    lista = new ArrayList<>();
//                    for (int i = 0; i < modeloRelacionTalla.getRowCount(); i++) {
//                        for (int j = 0; j < re.size(); j++) {
//                            if(re.get(j).getTallaid()==modeloRelacionTalla.get(i).getTallaid()){
//                                modeloRelacionTalla.get(i).setStock(re.get(j).getStock());
//                            }
//                        }
//                        lista.add(modeloRelacionTalla.get(i));                       
//                        
//                    }
//                    System.out.println("esto talla de lista de talla "+ lista.size());
//
//                    modeloRelacionTalla = new ModeloRelacionTalla(lista);
//                    jtTalla.setModel(modeloRelacionTalla);
//                    for (int i = 0; i < lista.size(); i++) {
//                        modeloRelacionTalla.add(lista.get(i));
//                    }
//
//                } catch (Exception e) {
//                    JOptionPane.showMessageDialog(this, "Error al cargar la lista. " + e, "Atención", JOptionPane.ERROR_MESSAGE);
//                }
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Error al asignar la talla", "Atención", JOptionPane.INFORMATION_MESSAGE);
        }
    }

    public int RetornaId(BEArticulo beec) {
        return beec.getArticuloid();
    }

}
